package org.ysu.shoeShopping.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.ysu.shoeShopping.dao.UsersDao;
import org.ysu.shoeShopping.entity.Users;
import org.ysu.shoeShopping.service.UsersService;

import java.util.List;

/**
 * 前台用户表(Users)表服务实现类
 */
@Service("usersService")
public class UsersServiceImpl implements UsersService
{
    @Autowired
    private UsersDao usersDao;


    /**
     * 新增数据
     *
     * @param users 实例对象
     * @return 实例对象
     */
    @Override
    public Users insert(Users users) {
        this.usersDao.insert(users);
        return users;
    }

    @Override
    public Boolean update(Users users)
    {
        return this.usersDao.update(users);
    }

    /**
     * 通过主键删除数据
     *
     * @param uid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer uid) {
        return this.usersDao.deleteById(uid) > 0;
    }

    @Override
    public Users findByUaccountAndUpwd(String uaccount, String upwd)
    {
        return this.usersDao.findByUaccountAndUpwd(uaccount,upwd);
    }

    @Override
    public Users findByUaccount(String uaccount)
    {

        return this.usersDao.findByUaccount(uaccount);
    }

    @Override
    public void updateAvatar(Long userId, String avatarUrl)
    {
        this.usersDao.updateAvatarUrl(userId, avatarUrl);
    }

    @Override
    public Users findByUid(Integer uid)
    {
        return this.usersDao.findByUid(uid);
    }

    @Override
    public boolean updatePassword(Integer uid, String newPassword) {
        return this.usersDao.updatePassword(uid, newPassword) > 0;
    }
    @Override
    public List<Users> findAllUsers() {
        return this.usersDao.findAllUsers();  // 假设这能返回所有用户的列表
    }

}
